/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package StringJoinerCutter;

import java.util.ArrayList;
import MyDataContainer.*;
import java.util.Arrays;
/**
 *
 * @author Welcome
 */
public class StringJoinerCutter {
    public static String getStringInMidle(String strStatement,String strBegin, String strEnd) throws Exception
    {
        strStatement = strStatement.toLowerCase();
        strBegin = strBegin.toLowerCase();
        strEnd = strEnd.toLowerCase();
        
        int tempBegin = strStatement.indexOf(strBegin); //danh dau vi tri bat dau
        int tempEnd = strStatement.indexOf(strEnd);     //danh dau vi tri ket thuc
        
        String result="";
        
        if(strBegin=="")
        {
            tempBegin =-1;
        }
        if (strEnd=="")
        {
            tempEnd =-1;
        }
        
        if (tempBegin !=-1) //co vi tri bat dau
        {
            if (tempEnd!=-1)
            {
                result= strStatement.substring(tempBegin+strBegin.length(), tempEnd).trim();
            }
            else
            {
                result= strStatement.substring(tempBegin+strBegin.length()).trim();
            }
        }
        else 
        {
            if (tempEnd!=-1)
            {
                result= strStatement.substring(0,tempEnd).trim();
            }
            else
            {
                return "";
            }
        }
        return result;
        //return null;
    }
    
    /**
     * Nối các String trong ArrayList thành 1 String, cách nhau dấu ","
     * @param stringList vd:mot hai ba
     * @return mot,hai,ba
     */
    public static String joinStringListToString(ArrayList<String> stringList)
    {
        String result ="";
        for(int i=0;i<stringList.size(); i++)
        {
            result = result+stringList.get(i)+",";
        }
        result = result.substring(0, result.length()-1);
        return result;
    }
    

    public static ArrayList<String> cutStringIntoStringList(String str)
    {
        String[] tempStrings = str.split(",");
        ArrayList<String> result=new ArrayList<String>();
        result.addAll(Arrays.asList(tempStrings));
        return result;
    }
    
}
